/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package classcreator;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;

/**
 *
 * @author Stefano
 */
public class Parameter {
    private static double outputFormatVersion=1.0;
    
    public Type type;
    public String name;
    
    public Parameter(Type t, String n){
        type=t;
        name=n;
    }
    
    public String toString(){
            return type.toString()+" "+name;
    }
    
    public static Parameter parse(BufferedReader br, TypeRepository tr) throws IOException{
                br.readLine();
                double version=Double.parseDouble(br.readLine());
                
                if(version<=1.0){
                    Type t=Type.parse(br, tr);
                    String name=br.readLine();
                    return new Parameter(t,name);
                }
                //Actual version
                Type t=Type.parse(br, tr);
                String name=br.readLine();
                return new Parameter(t,name);
    }
    
    public void permanentize(BufferedWriter br, TypeRepository tr) throws IOException{
        br.write("/***/ Parameter: "+name); br.newLine();
        br.write(String.valueOf(outputFormatVersion)); br.newLine();
                type.permanentize(br, tr); 
                br.write(name); br.newLine();
    }
}
